// import { useMemberStore } from '@/stores';

// 定义请求参数类型
type RequestOptions = UniApp.RequestOptions;

// 定义返回数据类型
type Data<T> = {
  code: string;
  msg: string;
  result: T;
};

// 定义请求函数
export const http = {
  get<T>(url: string, options?: RequestOptions): Promise<Data<T>> {
    return new Promise<Data<T>>((resolve, reject) => {
      uni.request({
        ...options,
        url,
        method: 'GET',
        success(res) {
          if (res.statusCode >= 200 && res.statusCode < 300) {
            resolve(res.data as Data<T>);
          } else {
            reject(res);
          }
        },
        fail(err) {
          reject(err);
        },
      });
    });
  },
};

// 调用请求函数获取随机图片
const getRandomImage = async () => {
  try {
    const response = await http.get<string>('https://imgapi.xl0408.top/index.php');
    console.log('Random image URL:', response.result);
  } catch (error) {
    console.error('Error fetching random image:', error);
  }
};

// 调用获取随机图片函数
getRandomImage();
